package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.restaurant.*;
import com.ocom.common.request.ugcapi.order.LoadRestaurantsRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.PointConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PointConfigController {

    @Autowired
    private PointConfigService pointConfigService;

    @PostMapping(PayConfigUrl.Url_restaurantList)
    public Result restaurantList(@RequestBody LoadRestaurantsRequest request) {
        return ResultUtil.success(pointConfigService.restaurantList(request.getComId(), request.getStrPoints(), request.getPointName(), request.getSize(), request.getPage()));
    }

    @PostMapping(PayConfigUrl.Url_newRestaurant)
    public Result newRestaurant(@RequestBody RestaurantAddRequest request) {
        return ResultUtil.success(pointConfigService.newRestaurant(request.getComId(),request));
    }

    @PostMapping(PayConfigUrl.Url_removeRestaurant)
    public Result removeRestaurant(@RequestBody RestaurantDeleteRequest request) {
        boolean result = pointConfigService.removeRestaurant(request.getComId(), request.getPointId());
        if (result) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(ResultEnum.Err_4069);
        }
    }

    @PostMapping(PayConfigUrl.Url_setRestaurantLogo)
    public Result setRestaurantLogo(@RequestBody RestaurantSetLogoRequest request) {
        boolean result = pointConfigService.setRestaurantLogo(request.getComId(), request.getPointId(), request.getLogoUrl());
        if (result) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(ResultEnum.Err_4069);
        }
    }

    @PostMapping(PayConfigUrl.Url_restaurantQrCode)
    public Result restaurantQrCode(@RequestBody RestaurantAppIdRequest request) {
        boolean result = pointConfigService.restaurantQrCode(request.getComId(), request.getPointId(), request.getAppid(), request.getImageUrl());
        if (result) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(ResultEnum.Err_4069);
        }
    }



    @PostMapping(PayConfigUrl.Url_saveRestaurantInfo)
    public Result saveRestaurantInfo(@RequestBody RestaurantInfoRequest request) {
        boolean result = pointConfigService.saveRestaurantInfo(request.getComId(), request.getPointId(), request.getAddress(), request.getRemark(),request.getLimitType());
        if (result) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(ResultEnum.Err_4069);
        }

    }

}
